package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.domain.StrategyContent;
import cn.wolfcode.trip.base.mapper.StrategyCatalogMapper;
import cn.wolfcode.trip.base.mapper.StrategyMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 13925 on 2018/11/4.
 */
@Service
public class StrategyCatalogServiceImpl implements IStrategyCatalogService {
    @Autowired
    private StrategyCatalogMapper strategyCatalogMapper;

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Strategy> list = strategyCatalogMapper.selectForList(qo);
        return new PageInfo(list);
    }

    public void saveOrUpdate(StrategyCatalog strategyCatalog) {
        //序列号自增长
        if (strategyCatalog.getSequence() == null) {
            int sequece = strategyCatalogMapper.selectAutoSequence(strategyCatalog.getStrategy().getId());
            strategyCatalog.setSequence(sequece);
        }

        //添加和编辑
        if (strategyCatalog.getId() != null) {
            strategyCatalogMapper.updateByPrimaryKey(strategyCatalog);
        } else {
            strategyCatalogMapper.insert(strategyCatalog);
        }
    }

    @Override
    public List<StrategyCatalog> getCatalogByStrategyId(Long strategyId) {
       return strategyCatalogMapper.selectCatalogByStrategyId(strategyId);
    }


}
